package top.lingkang.websocketlivechrome.ws;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/**
 * @author lingkang
 * Created by 2021/12/21
 */
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {
    @Autowired
    private AuthHandshakeInterceptor authHandshakeInterceptor;
    @Autowired
    private VideoWebSocketHandler videoWebSocketHandler;


    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(videoWebSocketHandler, "/ws")
                //拦截器，用于鉴权处理等
                .addInterceptors(authHandshakeInterceptor)
                //springwebsocket 4.1.5版本前默认支持跨域访问，之后的版本默认不开启支持跨域，需要设置.setAllowedOrigins("*")
                .setAllowedOrigins("*");
    }
}
